<?php

      // stateCode :  5 用户名和密码不匹配;

      // 1. 获取前端发送的数据;
      // 2. 链接数据库并查询;
      // 3. 返回结果;

      header("Content-type: text/html; charset=utf-8");
      header('Access-Control-Allow-Origin: *');

      $username = @$_POST["username"];
      $password = @$_POST["password"];
      $cookie = @$_COOKIE["password"];


     

      if($username === "" || $password === ""){
            die("账号密码均不能为空");
      }

      $db_username = "root";
      $db_password = "root";
      $db_host = "localhost:3306";

      $con = mysql_connect($db_host,$db_username,$db_password);

      if(!$con){
            $json_arr = array( "statu" => "error" , "stateCode" => "2" , "errorType" => "mySQL error".mysql_error());
            echo  json_encode($json_arr);
      }
      mysql_select_db("group7",$con);

      $select_SQL = "SELECT username_yzm,password_yzm FROM user_yzm";
      
      $select_res = mysql_query($select_SQL,$con);

      if($select_res){

            // if($cookie){
            //       $password = $cookie;
            // }else{
            //       $password = md5($password);
            // }

            while($row = mysql_fetch_array($select_res)){
                  if($row["username_yzm"] === $username && $row["password_yzm"] === $password){
                        $json_arr = array( "statu" => "success" , "stateCode" => "1");
                        die(json_encode($json_arr));
                  }
            }
      }

      $json_arr = array( "statu" => "error" , "stateCode" => "5", "errorType" => "User name password mismatch");
      die(json_encode($json_arr));
?>